#include "main.h"

char UI::tpName[9];

void UI::DrawCursor(unsigned char x, unsigned char y, char flag)
{
	if(flag)
	{
		Video::DrawLine(x, y, x + 1, y);
		Video::DrawLine(x, y + 1, x + 2, y + 1);
		Video::DrawLine(x, y + 2, x + 3, y + 2);
		Video::DrawLine(x, y + 3, x + 4, y + 3);
		Video::DrawLine(x, y + 4, x + 5, y + 4);
		Video::DrawLine(x, y + 5, x + 4, y + 5);
		Video::DrawLine(x, y + 6, x + 3, y + 6);
		Video::DrawLine(x, y + 7, x + 2, y + 7);
		Video::DrawLine(x, y + 8, x + 1, y + 8);
		Video::Update();
	}
	else
	{
		SDL_Rect r;
		r.h = 9;r.w = 6;r.x = x;r.y =y;
		Video::Clear(&r);
	}
}

void UI::DrawFlashCursor(unsigned char x, unsigned char y, char flag)
{
	if(flag)
	{
		Video::DrawLine(x, y, x + 7, y);
		++x;++y;
		Video::DrawLine(x, y, x + 5, y);
		++x;++y;
		Video::DrawLine(x, y, x + 3, y);
		++x;++y;
		Video::DrawLine(x, y, x, y);
	}
	else
	{
		SDL_Rect r;
		r.x = x;
		r.y = y;
		r.w = 7;
		r.h = 4;
		Video::Clear(&r);
	}
}

void UI::DrawPoint(unsigned char x, unsigned char y, int Num1, int Num2)
{
	int offset = Video::DrawPtNumber(x, y, Num1);
	Video::DrawPtNumber(x + 4 * offset, y, -1);
	Video::DrawPtNumber(x + 4 * (1 + offset), y, Num2);
}

void UI::DrawSelectRect(unsigned char x, unsigned char y, char flag)
{
	if(flag)
		Video::FillRect(x, y, 6, 6);
	else
		Video::DrawRect(x, y, 6, 6);
}

void UI::DrawProgressBox(unsigned short n1, unsigned short n2, unsigned short pt, unsigned short lv)
{
	SDL_Rect r;
	unsigned int w = 0;
	r.h = 8;
	r.w = WQX_ORG_WIDTH;
	r.x = 0;
	r.y = 1;
	Video::Clear(&r);
	Video::DrawRect(30, 1, 65, 8);
	if(n2)
		w = n1 * 65 / n2;
	else
		w = 0;
	Video::FillRect(30, 1, w, 8);
	w = Video::DrawPtNumber(30+65+8, 3, pt);
	Video::DrawPtNumber(30+65+8+4*w, 3, -1);
	Video::DrawPtNumber(30+65+8+4*w+4, 3, lv);
}
unsigned int UI::Gmud_WaitForKey(unsigned int Time)
{
   unsigned int TimeOut = SDL_GetTicks() + Time;
   Input::ClearKeyStatus();
   while (Time == 0 || SDL_GetTicks() < TimeOut)
   {
      GmudDelay(5);
      if(Input::State.KeyPress)
      {
         return Input::State.KeyPress;
      }
   }
   return 0;
}

void UI::InputName()
{
	Input::Name();
}